<%-- 
    Document   : manageAccount
    Created on : Oct 8, 2012, 6:54:05 PM
    Author     : Nhan
--%>

<%@page import="com.User"%>
<%@page import="com.Checker"%>
<%@page import="com.Book"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Manage Account Page</h1>
        <table border="1" cellspacing="0">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Username</th>
                    <th>First Name</th>
                    <th>Role</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <%
                    ArrayList<User> searhResult = Checker.getAllAccount();
                    int index = 0;
                    if (searhResult.size() != 0) {
                        for (User user : searhResult) {
                            index++;
                            String username = user.getUsername();
                            String firstname = user.getFirstName();
                            String role = user.getRole();
                            String status = user.getStatus().trim().toUpperCase();
                            String buttonValue = "";

                            if(status.equals("ACTIVE")) {
                                buttonValue = "Suspend";
                            } else if(status.equals("UNACVTIVE") || status.equals("SUSPEND")) {
                                buttonValue = "ACTIVE";
                            } else {
                                buttonValue = "ACTIVE";
                            }
                           
                %>

                <tr>
                    <td><%= index %></td>
                    <td><%= username %></td>
                    <td><%= firstname %></td>
                    <td><%= role %></td>
                    <td><%= status %></td>

                     <td>
                         <form action="../centralUnit" method="GET">
                             <input type="hidden" name="usernameToChange" value="<%= username %>" />
                           <input type="submit" name="action" value="<%= buttonValue %>" size="" />
                        </form>
                    </td>

                </tr>
                <% }
                           } else {%>

                <tr><td colspan="6"><h3>There are no account to manage!</h3></tr>

                <% }

                %>
            </tbody>
        </table>
    </body>
</html>
